#define _CRT_SECURE_NO_WARNINGS
#include"add.h"
void QueueInit(Que* pq) {
	assert(pq);
	pq->head = NULL;
	pq->tail = NULL;
	pq->size = 0;
}
void QueueDestroy(Que* pq) {
	assert(pq);
	QNode* cur = pq->head;
	while (cur) {
		QNode* next = cur->next;
		free(cur);
		cur = next;
	}
	pq->head = NULL;
	pq->tail = NULL;
	pq->size = 0;
}
void QueuePush(Que* pq, QDataType x) {
	assert(pq);
	QNode* newnode = (QNode*)malloc(sizeof(QNode));
	if (newnode == NULL) {
		perror("malloc fail");
		exit(-1);
	}
	newnode->data = x;
	newnode->next = NULL;
	if (pq->head == NULL) {
		pq->head = pq->tail = newnode;
	}
	else {
		pq->tail->next = newnode;
		pq->tail = pq->tail->next;
		pq->tail->next = NULL;
	}
	pq->size++;
}
void QueuePop(Que* pq) {
	assert(pq);
	assert(pq->size > 0);
	if (pq->head == pq->tail) {
		free(pq->head);
		pq->head = pq->tail = NULL;
		pq->size = 0;
	}
	else {
		QNode* tmp = pq->head;
		pq->head = pq->head->next;
		free(tmp);
		pq->size--;
	}
	
}

QDataType QueueFront(Que* pq) {
	assert(pq);
	assert(pq->size > 0);
	return pq->head->data;
}

QDataType QueueBack(Que* pq) {
	assert(pq);
	assert(pq->size > 0);
	return pq->tail->data;
}
bool QueueEmpty(Que* pq) {
	assert(pq);
	return pq->size == 0;
}
int QueueSize(Que* pq) {
	assert(pq);
	return pq->size;
}






/*
void STInit(ST* st) {
	assert(st);
	st->a = NULL;
	st->top = 0;
	st->capacity = 0;
}

void STDestroy(ST* st) {
	assert(st);
	free(st->a);
	st->a = NULL;
	st->top = 0;
	st->capacity = 0;
}

void STPush(ST* st, STDataType x) {
	assert(st);
	if (st->top == st->capacity) {
		int newcapacity = st->capacity == 0 ? 4 : st->capacity * 2;
		STDataType* tmp = (STDataType*)realloc(st->a, sizeof(STDataType) * newcapacity);
		if (tmp == NULL) {
			perror("realloc fail");
			exit(-1);
		}
		st->a = tmp;
		st->capacity = newcapacity;
	}
	st->a[st->top] = x;
	st->top++;
}

void STPop(ST* st) {
	assert(st);
	assert(st->top > 0);
	st->top--;
}

STDataType STTop(ST* st) {
	assert(st);
	assert(st->top > 0);
	return st->a[st->top - 1];
}

int STSize(ST* st) {
	assert(st);
	return st->top;
}

bool STEmpty(ST* st) {
	assert(st);
	return st->top == 0;
}*/